<?php
include_once dirname(__FILE__).'/../../factory/DAOFactory.php';
include_once dirname(__FILE__).'/../dao/ArtifactHasTagDAO.php';
include_once dirname(__FILE__).'/../dao/AttributeDAO.php';
include_once dirname(__FILE__).'/../dao/AttributeGroupDAO.php';
include_once dirname(__FILE__).'/../dao/AttributeInGroupDAO.php';
include_once dirname(__FILE__).'/../dao/CommentDAO.php';
include_once dirname(__FILE__).'/../dao/ProjectDAO.php';
include_once dirname(__FILE__).'/../dao/ProjectFolderDAO.php';
include_once dirname(__FILE__).'/../dao/RequirementDAO.php';
include_once dirname(__FILE__).'/../dao/RequirementHasAttributeGroupDAO.php';
include_once dirname(__FILE__).'/../dao/RequirementRevisionDAO.php';
include_once dirname(__FILE__).'/../dao/SavedFilterDAO.php';
include_once dirname(__FILE__).'/../dao/SavedFilterHasArtifactDAO.php';
include_once dirname(__FILE__).'/../dao/TagDAO.php';
include_once dirname(__FILE__).'/../dao/UserDAO.php';
include_once dirname(__FILE__).'/../dao/UserJoinProjectDAO.php';
include_once dirname(__FILE__).'/../dao/UserUpdateArtifactDAO.php';


/**
 * Name: RDBDAOFactory.php
 * Created by: Chung Hoang Long
 * Created Date: 11-10-2013
 * Description: Xu ly du lieu DBMS
 */

class RDBDAOFactory extends DAOFactory {
	
	private $conn;
	/**
	 * Tao ket noi den CSDL Relational DB
	 * @param RDBConfig $rdbConfig
	 * @return PDO
	 */	
	public static function createConnection($rdbConfig) {
		$rdbConfig = new RDBConfig(RDBConfig::$DEFAULT_HOST, RDBConfig::$DEFAULT_DBNAME,
				RDBConfig::$DEFAULT_USERNAME, RDBConfig::$DEFAULT_PASSWORD);
// 		$this->conn = mysqli_connect($rdbConfig->getHost(), $rdbConfig->getUserName(),
// 				$rdbConfig->getPassword(), $rdbConfig->getDBName());
		
		try {
			$conn = new PDO('mysql:host='.$rdbConfig->getHost().';dbname='.$rdbConfig->getDBName(),
					$rdbConfig->getUserName(), $rdbConfig->getPassword());
// 			publish du an thi thay doan code nay
// 			$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
			$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		} catch (PDOException $exc) {
			// xuat thong bao
			echo $exc->getMessage();
			// ghi logs
		}
		
		return $conn;
		
	}
	
	public function getArtifactHasTagDAO() {
		return new ArtifactHasTagDAO();
	}
	
	public function getAttributeDAO() {
		return new AttributeDAO();
	}
	
	public function getAttributeGroupDAO() {
		return new AttributeGroupDAO();
	}
	
	public function getAttributeInGroupDAO() {
		return new AttributeInGroupDAO();
	}
	
	public function getCommentDAO() {
		return new CommentDAO();
	}
	
	public function getProjectDAO() {
		return new ProjectDAO();
	}
	
	public function getProjectFolderDAO() {
		return new ProjectFolderDAO();
	}
	
	public function getRequirementDAO() {
		return new RequirementDAO();
	}
	
	public function getRequirementHasAttributeGroupDAO() {
		return new RequirementHasAttributeGroupDAO();
	}
	
	public function getRequirementRevisionDAO() {
		return new RequirementRevisionDAO();
	}
	
	public function getSavedFilterDAO() {
		return new SavedFilterDAO();
	}
	
	public function getSavedFilterHasArtifactDAO() {
		return new SavedFilterHasArtifactDAO();
	}
	
	public function getTagDAO() {
		return new TagDAO();
	}
	
	public function getUserDAO() {
		return new UserDAO();
	}
	
	public function getUserJoinProjectDAO() {
		return new UserJoinProjectDAO();
	}
	
	public function getUserUpdateArtifactDAO() {
		return new UserUpdateArtifactDAO();
	}
	
}
?>